package jp.sourceforge.akjrcp.audio;

public class Scale {
	//0 is C
public static final int[] MAJOR_SCALE={0,2,4,5,7,9,11};
public static final int[] MINOR_SCALE={0,2,3,5,7,8,10};
public static final int SCALE_C=0;
public static final int SCALE_D=2;
public static final int SCALE_E=4;
public static final int SCALE_F=5;
public static final int SCALE_G=7;
public static final int SCALE_A=9;
public static final int SCALE_B=11;

public static final String LABEL_C="C";
public static final String LABEL_D="D";
public static final String LABEL_E="E";
public static final String LABEL_F="F";
public static final String LABEL_G="G";
public static final String LABEL_A="A";
public static final String LABEL_B="B";

public static final int[] CODE_MAJOR={0,4,7};

public static final int[] CODE_AUG={0,4,8};
public static final int[] CODE_FLAT_FIVE={0,4,6};
public static final int[] CODE_SIX={0,4,7,9};
public static final int[] CODE_MAJOR_SEVEN={0,4,7,11};
public static final int[] CODE_MAJOR_NINES={0,4,7,11,14};

public static final int[] CODE_SEVEN={0,4,7,10};
public static final int[] CODE_SEVEN_FLAT_FIVE={0,4,6,10};
public static final int[] CODE_SEVEN_AUG={0,4,8,10};

public static final int[] CODE_SIX_NINE={0,4,7,9,14};
public static final int[] CODE_NINES={0,4,7,10,14};
public static final int[] CODE_SEVEN_FLAT_NINES={0,4,7,10,13};
public static final int[] CODE_MINOR={0,3,7};

public static final String LABEL_AUG="aug";
public static final String LABEL_FLAT_FIVE="b5";
public static final String LABEL_SIX="6";
public static final String LABEL_MAJOR_SEVEN="M7";
public static final String LABEL_MAJOR_NINES="M9";

public static final String LABEL_SEVEN="7";
public static final String LABEL_SEVEN_FLAT_FIVE="7b5";
public static final String LABEL_SEVEN_AUG="7+5";

public static final String LABEL_SIX_NINE="69";
public static final String LABEL_NINES="9";
public static final String LABEL_SEVEN_FLAT_NINES="7b9";

public static final String LABEL_MINOR="m";
private static int[] shiftCode(int values[],int code){
	int[] ret=new int[values.length];
		
		for (int i = 0; i < ret.length; i++) {
			ret[i]=values[i]+code;
			if(ret[i]!=0){
				ret[i]=ret[i]%12;
			}
		}
		
		return ret;
	}


public static int[] getMajorScale(int code){
	return shiftCode(MAJOR_SCALE,code);
}

public static int[] getMinorScale(int code){
	return shiftCode(MINOR_SCALE,code);
}

public static int[] getMinorCode(int code){
	return shiftCode(CODE_MINOR,code);
}

public static int[] getMajorCode(int code){
	return shiftCode(CODE_MAJOR,code);
}

public static int[] getCodeScale(String code){
	
	int scale=stringToScale(code.substring(0,1));
	int codes[]=stringToCode(code.substring(1));
	return shiftCode(codes,scale);
}

public static int[] stringToCode(String str){
	
	if(str.equals(LABEL_AUG)){
		return CODE_AUG;
	}
	if(str.equals(LABEL_FLAT_FIVE)){
		return CODE_FLAT_FIVE;
	}
	if(str.equals(LABEL_SIX)){
		return CODE_SIX;
	}
	if(str.equals(LABEL_MAJOR_SEVEN)){
		return CODE_MAJOR_SEVEN;
	}
	if(str.equals(LABEL_MAJOR_NINES)){
		return CODE_MAJOR_NINES;
	}
	if(str.equals(LABEL_SEVEN)){
		return CODE_SEVEN;
	}
	if(str.equals(LABEL_SEVEN_FLAT_FIVE)){
		return CODE_SEVEN_FLAT_FIVE;
	}
	if(str.equals(LABEL_SIX_NINE)){
		return CODE_SIX_NINE;
	}
	if(str.equals(LABEL_NINES)){
		return CODE_NINES;
	}
	if(str.equals(LABEL_SEVEN_AUG)){
		return CODE_SEVEN_AUG;
	}
	if(str.equals(LABEL_SEVEN_FLAT_NINES)){
		return CODE_SEVEN_FLAT_NINES;
	}
	if(str.equals(LABEL_MINOR)){
		return CODE_MINOR;
	}
	
	return CODE_MAJOR;
}
public static int stringToScale(String str){
	if(str.length()==1){
		if(str.equals("C")){
			return SCALE_C;
		}
		if(str.equals("D")){
			return SCALE_D;
		}
		if(str.equals("E")){
			return SCALE_E;
		}
		if(str.equals("F")){
			return SCALE_F;
		}
		if(str.equals("G")){
			return SCALE_G;
		}
		if(str.equals("A")){
			return SCALE_A;
		}
		if(str.equals("B")){
			return SCALE_B;
		}
	}
	
	return SCALE_C;
}


}
